package com.doit.day03;


import com.doit.day02.Hero;
import com.doit.day02.MyIterator;

import java.util.Iterator;

public class _01_可迭代的 {
    public static void main(String[] args) {

        MyIterable heroes = new MyIterable();
        for (Hero hero : heroes) {
            System.out.println(hero);
        }


        Iterator<Hero> iterator = heroes.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }



    }
}


//为什么iterable 有可迭代的这样的属性 ==》 我有迭代器
class MyIterable implements Iterable<Hero>{

    @Override
    public Iterator<Hero> iterator() {
        MyIterator myIterator = null;
        try {
            myIterator = new MyIterator();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return myIterator;
    }
}
